********************************************************************************
** 	TITLE: e18_peopleinjail_daily.do
**
**	PROJECT: IGNITE
** 
**  PURPOSE: Appendix Figure XVIII: Genesee and Saginaw Jail Populations

********************************************************************************
**  PURPOSE: Jail population scaled by the capacity of each jail over time
**	Note: Genesee County - constrained data (booked between 01/2016 to 05/2022)
********************************************************************************

* Saginaw
*****************************
//Bring in Saginaw Data and keep estimate sample and their 2015 equivalent. 
use "$output_data/sag_appended.dta", clear
keep if any_case_nr & booking_date>=date("01/01/2015","MDY") ///
		& booking_date<date("06/01/2022","MDY")&!missing(release_date)

keep inmate booking_date release_date

egen ID = group(inmate booking_date)

format %td booking_date

gen duration = release_date - booking_date + 1
drop if missing(duration)
expand duration

bysort ID: gen jail_date = booking_date + _n-1
format  %td jail_date

gen population = 1
collapse (sum) population, by(jail_date)
replace population  = population/511 //Jail capacity in Saginaw is 511	//https://www.mlive.com/news/saginaw-bay-city/2020/02/more-doors-fewer-bars-a-look-inside-the-new-35-million-saginaw-county-jail.html
	//https://web.archive.org/web/20240718060016/https://www.saginawcounty.com/courts-public-safety/sheriff/

gen data= 2

tempfile sag_data
save `sag_data', replace


* Genesee
*****************************
//Bring in Genesee Data and keep estimate sample and their 2015 equivalent (prediction sample) 

use "$output_data/prediction.dta", clear

keep inmate booking_date release_date

egen ID = group(inmate booking_date)

format %td booking_date

gen duration = release_date - booking_date + 1
drop if missing(duration)
expand duration

bysort ID: gen jail_date = booking_date + _n-1
format  %td jail_date

gen population = 1
collapse (sum) population, by(jail_date)
replace population  = population/580 //Jail capacity of Genesee County is 580
	//http://web.archive.org/web/20240422001459/https://www.gcsomichigan.com/corrections-division 

gen data=1

//Append Saginaw Data to Genesee Data
append using `sag_data'

reshape wide population, i(jail_date) j(data)

preserve
* 2021
keep if inrange(jail_date, td(01jan2016), td(31jul2021))
	
twoway line  population1 jail_date, sort ytitle("Jail Population/Capacity") ylabel(0(0.2)1.2) ymtick(0(0.2)1.2) lcolor(ebblue) || ///
	   line  population2 jail_date, sort  lcolor(cranberry) ///
	   legend(order(1 "Genesee" 2 "Saginaw") position(6) cols(2)) xtitle("Date") ///
	   xline(22159, lwidth(*2) lc(gs8) lp(solid)) xline(21975, lwidth(*2) lc(gs8) lp(dash_dot)) ///
	ttext(1 22281 "IGNITE", size(*.85)) ttext(1 21854 "COVID", size(*.85)) xlabel(20454 20820 21185 21550 21915 22281, format(%td)) graphregion(fcolor(white)) ///
bgcolor(white) yla(, nogrid) xla(, nogrid) 

	gr export "$figures/people_in_jail_gen_sag_end072021.pdf", replace
